package com.fly.docker.web;

import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import com.fly.core.utils.DockerUtils;
import com.fly.docker.service.DockerService;

import io.swagger.annotations.Api;

/**
 * 
 * ShowController
 * 
 * @author 00fly
 * @version [版本号, 2020-04-16]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Api(tags = "传统模式接口")
@Controller
@ConditionalOnWebApplication
public class ShowController
{
    @Autowired
    DockerService dockerService;
    
    /**
     * docker应用列表
     * 
     * @param model
     * @return
     * @throws Exception
     * @see [类、类#方法、类#成员]
     */
    @GetMapping("/show")
    public String show(Model model)
    {
        // lambda实现List2Map
        model.addAttribute("map", dockerService.getClients().stream().collect(Collectors.toMap(DockerUtils::host, DockerUtils::containers, (key1, key2) -> key2)));
        return "show";
    }
}
